﻿@namespace ThingsGateway.Gateway.Razor
@using ThingsGateway.Admin.Application
@using ThingsGateway.Admin.Razor
@using ThingsGateway.Debug
@using ThingsGateway.Gateway.Application
@using ThingsGateway.Extension
@inherits ComponentDefault


@* class=@((Item.CurrentDevice?.DeviceStatus==DeviceStatusEnum.OnLine?"green--text mx-1":"red--text mx-1")) *@
<div class="device">
    <Card class="mb-2">

        <HeaderTemplate>

            <span class=@("text-h6 mx-1") style="overflow:auto;">
                <span style="white-space: nowrap !important;overflow: hidden !important; text-overflow: ellipsis !important;"
                      title=@Item.CurrentDevice?.Name>@Item.CurrentDevice?.Name</span>
            </span>

            <div style="flex-grow: 1;"></div>
            @if (Item?.DriverUIType != null)
            {
                <Tooltip Title="@Localizer["GatewayDeviceShowDriverUI"]" Placement="Placement.Bottom">

                    <Button OnClick=@(ShowDriverUI) IsDisabled=@(!AuthorizeButton("插件页面")) class="mx-2" Color="Color.None" style="color: var(--bs-card-titlecolor);" Icon=@("fab fa-simplybuilt") />
                </Tooltip>

            }

            @if (Item?.CurrentDevice.RedundantEnable == true)
            {
                <Tooltip Title="@Localizer["DeviceRedundantThread"]" Placement="Placement.Bottom">
                    <PopConfirmButton OnConfirm=@(()=>DeviceRedundantThreadAsync(Item.DeviceId)) IsDisabled=@(!AuthorizeButton("切换冗余")) class="mx-2" Color="Color.None" style="color: var(--bs-card-title-color);" Icon=@("fas fa-exchange-alt") />
                </Tooltip>

            }

            @if (Item?.IsCollectDevice == false)
            {
                <Tooltip Title="@Localizer["DeleteCache"]" Placement="Placement.Bottom">
                    <PopConfirmButton OnConfirm=@(()=>DeleteCacheAsync(Item.CurrentDevice)) IsDisabled=@(!AuthorizeButton("删除缓存")) class="mx-2" Color="Color.None" style="color: var(--bs-card-title-color);" Icon=@("fa-solid fa-rotate") />
                </Tooltip>
            }
            <Tooltip Title="@Localizer["RelationVariable"]" Placement="Placement.Bottom">

                <Button OnClick=@(()=>RelationVariable(Item.DeviceId)) class="mx-2" Color="Color.None" style="color: var(--bs-card-title-color);" Icon="fa-solid fa-people-roof" />
            </Tooltip>
            <Tooltip Title="@Localizer["GatewayDeviceLog"]" Placement="Placement.Bottom">

                <Button OnClick=@(SetLogEnable) IsDisabled=@(!AuthorizeButton("通道日志")) class="mx-2" Color="Color.None" style="color: var(--bs-card-title-color);" Icon=@(Item.ChannelThread.LogEnable?"fa fa-pause":"fa fa-play") />
            </Tooltip>

            <Tooltip Title="@Localizer["GatewayDevicePause"]" Placement="Placement.Bottom">

                <Button OnClick=@(()=>PauseThread(Item.DeviceId,!Item.CurrentDevice?.KeepRun)) IsDisabled=@(!AuthorizeButton("暂停")) class="mx-2" Color="Color.None" style="color: var(--bs-card-title-color);" Icon=@(Item.CurrentDevice.KeepRun?"fa fa-pause":"fa fa-play") />
            </Tooltip>

            <Tooltip Title="@Localizer["GatewayDeviceRestart"]" Placement="Placement.Bottom">

                <PopConfirmButton OnConfirm=@(()=>RestartAsync(Item.DeviceId)) IsDisabled=@(!AuthorizeButton("重启")) class="mx-2" Color="Color.None" style="color: var(--bs-card-title-color);" Icon=@("fa-solid fa-rotate") />
            </Tooltip>



        </HeaderTemplate>

        <BodyTemplate>
            <div style="overflow-y:auto ;overflow-x:hidden ; height:200px;">

                <DeviceStatus3 Item="@Item"></DeviceStatus3>
                <EditorFormObject class="mt-2"   Items="@Item.PluginPropertyEditorItems" Model=@Item.DriverProperties AutoGenerateAllItem=false IsDisplay LabelWidth="80" RowType="RowType.Inline" ItemsPerRow="3" ShowLabelTooltip="true" @key=Item.DriverProperties.GetHashCode()>
                    <FieldItems>
                        @if (Item.DriverProperties is BusinessPropertyWithCacheIntervalScript businessProperty)
                        {
                            <EditorItem FieldExpression=@(()=>context) Field=@(context)>

                                <EditTemplate Context="value">
                                    <div class="col-12  col-md-12">

                                        <Textarea @bind-Value=@businessProperty.BigTextScriptDeviceModel ShowLabelTooltip="true"
                                                  rows="5" ShowLabel="true" IsDisabled />
                                        <div class="ms-2 d-flex justify-content-center align-items-center">
                                       
                                        </div>
                                    </div>
                                    <div class="col-12  col-md-12">
                                        <Textarea @bind-Value=@businessProperty.BigTextScriptVariableModel ShowLabelTooltip="true"
                                                  rows="5" ShowLabel="true" IsDisabled />
                                        <div class="ms-2 d-flex justify-content-center align-items-center">
                                        
                                        </div>
                                    </div>
                                    <div class="col-12  col-md-12">
                                        <Textarea @bind-Value=@businessProperty.BigTextScriptAlarmModel ShowLabelTooltip="true"
                                                  rows="5" ShowLabel="true" IsDisabled  />
                                        <div class="ms-2 d-flex justify-content-center align-items-center">
                                  
                                        </div>
                                    </div>

                                </EditTemplate>
                            </EditorItem>
                        }
                    </FieldItems>
                </EditorFormObject>
            </div>
        </BodyTemplate>
    </Card>


</div>
